package iflyer.web;

import iflyer.bean.ResultBean;
import iflyer.model.ProductCategory;
import iflyer.service.ProductCategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

/**
 * @ClassName ProductController
 * @Author babylct
 * @Date 2018/7/18 8:53
 * @Version 1.0
 */
@RestController
@RequestMapping("/buyer/product")
public class ProductCategoryController {

    @Autowired
    private ProductCategoryService productCategoryService;

//    @Autowired
//    private ProductCategoryRepository productCategoryRepository;

    @GetMapping("/list")
    public ResultBean list() {
        ResultBean resultBean = new ResultBean();

//        //查询所有上架商品
//        List<ProductInfo> infoList = productInfoService.findUpAll();
//        //查询类目（一次性查询）
//        List<String> categoryTypeList = infoList.stream().map(
//                e -> e.getCategoryType()).collect(Collectors.toList());
//
//        List<ProductCategory> productCategoryList =
//                productCategoryService.findByCategoryTypeIn(categoryTypeList);
//        //数据拼接
        ProductCategory productCategory = new ProductCategory();
        productCategory.setCategoryName("鞋子");
        productCategory.setCategoryType("001");
        productCategory.setCreator("SYSTEM");
        productCategory.setModifier("SYSTEM");
        productCategory.setGmtCreate(new Date());
        productCategory.setGmtModified(new Date());
        productCategoryService.save(productCategory);

        //productCategory = productCategoryRepository.findByCategoryName("鞋子");
        resultBean.setCode("1");
        resultBean.setData(productCategory);
        resultBean.setMsg("success");
        return resultBean;
    }
}
